#include "VertexList.h"

VertexList::VertexList()
{
}

VertexList::~VertexList()
{

}

void VertexList::addVertex(float x, float y, float z)
{
	if (m_Vertices.size() == 0)
	{
		m_maxVertex = Vertex(x, y, z);
		m_minVertex = Vertex(x, y, z);
	}

	m_Vertices.push_back(Vertex(x, y, z));

	if(x >= m_maxVertex.x) m_maxVertex.x = x;
	else if (x <= m_minVertex.x) m_minVertex.x = x;

	if(y >= m_maxVertex.y) m_maxVertex.y = y;
	else if (y <= m_minVertex.y) m_minVertex.y = y;

	if(z >= m_maxVertex.z) m_maxVertex.z = z;
	else if (z <= m_minVertex.z) m_minVertex.z = z;
}

Vertex VertexList::getVertex(int pos)
{
	return m_Vertices[pos];
}

void VertexList::drawBoundingBox()
{
	glColor3ub(0,0,255);
	glBegin(GL_LINE_LOOP); 
		glVertex3f(m_maxVertex.x, m_minVertex.y, m_minVertex.z);
		glVertex3f(m_maxVertex.x, m_maxVertex.y, m_minVertex.z);
		glVertex3f(m_minVertex.x, m_maxVertex.y, m_minVertex.z);
		glVertex3f(m_minVertex.x, m_minVertex.y, m_minVertex.z);
		glVertex3f(m_maxVertex.x, m_minVertex.y, m_minVertex.z);
	glEnd();

	glBegin(GL_LINE_LOOP); 
		glVertex3f(m_maxVertex.x, m_minVertex.y, m_maxVertex.z);
		glVertex3f(m_maxVertex.x, m_maxVertex.y, m_maxVertex.z);
		glVertex3f(m_minVertex.x, m_maxVertex.y, m_maxVertex.z);
		glVertex3f(m_minVertex.x, m_minVertex.y, m_maxVertex.z);
		glVertex3f(m_maxVertex.x, m_minVertex.y, m_maxVertex.z);
	glEnd();

	glBegin(GL_LINES);
		glVertex3f(m_maxVertex.x, m_minVertex.y, m_minVertex.z);
		glVertex3f(m_maxVertex.x, m_minVertex.y, m_maxVertex.z);

		glVertex3f(m_maxVertex.x, m_maxVertex.y, m_minVertex.z);
		glVertex3f(m_maxVertex.x, m_maxVertex.y, m_maxVertex.z);

		glVertex3f(m_minVertex.x, m_minVertex.y, m_minVertex.z);
		glVertex3f(m_minVertex.x, m_minVertex.y, m_maxVertex.z);

		glVertex3f(m_minVertex.x, m_maxVertex.y, m_minVertex.z);
		glVertex3f(m_minVertex.x, m_maxVertex.y, m_maxVertex.z);
	glEnd();
}